﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Text;
using QZone.crlclr.album.data;

namespace QZone.crlclr.album
{
    public class AlbumsXMLLoader:URLLoader
    {

        public List<Album> albums;

        public AlbumsXMLLoader()
        {
            albums = new List<Album>();
        }

        /// <summary>
        ///  下载QQ相册列表配置文件;
        /// </summary>
        /// <param name="qqcode"></param>
        public void loadQQ(string qqcode)
        {
            albums.Clear();

            string path = string.Format(QQZoneManager.getAlbumTemplet(), qqcode);

            string xmlString=this.load(path);

            if (String.IsNullOrEmpty(xmlString))
            {
                //加载过程中出错;
                return;
            }

          
            xml= new XmlDocument();
            try
            {
                xml.LoadXml(xmlString);
            }
            catch (Exception e)
            {
                xml.LoadXml(string.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?><error>{0}</error>",e.Message));
            }
            XmlNodeList list=xml.ChildNodes[1].ChildNodes;

            Album album;
            foreach (XmlElement item in list)
            {
                if (item.LocalName != "album") continue;
                album = new Album(qqcode);
                album.bindXML(item);
                albums.Add(album);
            }
        }

 
    }
}
